package 剑指offer;

import org.junit.jupiter.api.Test;

import java.security.cert.CollectionCertStoreParameters;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class 数据流中的中位数 {
    class MedianFinder {
        /** initialize your data structure here. */
        ArrayList<Integer> list;
        public MedianFinder() {
             list=new ArrayList<>();
        }

        public void addNum(int num) {
              list.add(num);
        }

        public double findMedian() {
            Collections.sort(list);
            if (list.size()%2==1)
                return list.get(list.size()/2);
            double m = list.get(list.size() / 2);
            double n = list.get(list.size() / 2-1);
            return (m+n)/2;
        }
    }
    @Test
    public void test(){
        double m= (double) 1;
        double n= 2 ;
        double v = (m + n) / 2;
        System.out.println(v);
    }
}
